jQuery(document).ready(function(){		
	jQuery('.paginate_button').click(function(){				
		showAjaxEffect();				
	});	
	jQuery('#applyChange').click(function(){					
		var action = jQuery('#action').val();
		if(action=='0'){
			alert('Please choose action !');
		}else if(action=='1'){
			var ids = '';
			var count = 0;
			jQuery('#table-result tbody tr td input[type=checkbox]').each(function (item, data) {
				if (jQuery(this).is(':checked')) {				
					ids += jQuery(this).val() + ',';
					count++;
				}
			});		
			if(count>0){
				if(confirm('All checked feedback will be delete !')){
					showAjaxEffect();
					jQuery.get('/admin/feedback/process', {ids: ids, action: 'delete-all'}, function(data) {
						hideAjaxEffect();	
						scrollToTop();
						if(data==''){
							jQuery('#table-result tbody tr td input[type=checkbox]').each(function (item, data) {
								if (jQuery(this).is(':checked')) {				
									jQuery(this).parents("tr").remove();						
								}
							});
							jQuery('#messageDiv').fadeIn();
							jQuery('#messageDiv').addClass('msgsuccess').removeClass('hidden');
							jQuery('#messageDiv > p').html('Action success ! Feedbacks have been deleted');
							setTimeout(function() {
								jQuery('#messageDiv').fadeOut();
							}, 2000);																
						}else{
							jQuery('#messageDiv').fadeIn();
							jQuery('#messageDiv').addClass('msgerror').removeClass('hidden');
							jQuery('#messageDiv > p').html(data);
							setTimeout(function() {
								jQuery('#messageDiv').fadeOut();
							}, 2000);	
						}		
					});
				}else{
					return false;
				}				
			}else{
				alert('Please check some feedback to do this action !');
			}				
		}
	});			
	jQuery('.btnDelete').click(function(){			
		if(confirm('Are you sure want to delete this feedback ?')){		
			var temp = jQuery(this);
			showAjaxEffect();
			jQuery.get('/admin/feedback/process', { 
				action: 'delete', 
				id: jQuery(this).attr('href'), 
					} ,
				function( data ) {
					hideAjaxEffect();
					scrollToTop();
					if(data==''){			
						temp.parents('tr').remove();	
						jQuery('#messageDiv').fadeIn();
						jQuery('#messageDiv').addClass('msgsuccess').removeClass('hidden');
						jQuery('#messageDiv > p').html('Action success ! Feedback has been deleted');
						setTimeout(function() {
							jQuery('#messageDiv').fadeOut();
						}, 2000);																
					}else{
						jQuery('#messageDiv').fadeIn();
						jQuery('#messageDiv').addClass('msgerror').removeClass('hidden');
						jQuery('#messageDiv > p').html(data);
						setTimeout(function() {
							jQuery('#messageDiv').fadeOut();
						}, 2000);	
					}	
	     		}
			);				
		}
		return false;
	}); 	
});

